package com.xinqing.test.LetCode;

import java.util.Arrays;

/**
 * @Author:CHQ
 * @Date:2021/7/22 11:09
 * @Description
 */
public class FindUnsortedSubarray {
    public static void main(String args[]){


        int[] nums={2,6,4,8,10,9,15};
        System.out.println(test(nums));
    }
    public static int test(int[] nums){
        int start=Integer.MAX_VALUE;
        int end=Integer.MIN_VALUE;
       int[] cloneNums= nums.clone();
       Arrays.sort(cloneNums);

       for(int i=0;i<nums.length;i++){
           if(nums[i]!=cloneNums[i]){
               start=Math.min(start,i);
               end=Math.max(end,i);
           }
       }
       return (end-start)>0?(end-start+1):0;
    }
}
